import { EnumSchema } from '#/common';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** IoT网关协议类型枚举 */
export enum IoTGatewayProtocolTypeEnum {
  /** MQTT协议 */
  MQTT = 100,
  // /** OPCUA协议 */
  // OPCUA = 200,
}

/** IoT网关协议类型实体 */
export class IoTGatewayProtocolTypeEntity {
  /** IoT网关协议类型 */
  ProtocolType: IoTGatewayProtocolTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(protocolType: IoTGatewayProtocolTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.ProtocolType = protocolType;
    this.Color = color;
    switch (protocolType) {
      case IoTGatewayProtocolTypeEnum.MQTT:
        // this.Display = 'MQTT协议';
        this.Display = t('iot.enum.ioTGatewayProtocolType.mqtt');
        this.Color = this.Color ? this.Color : PresetColorEnum.Magenta;
        break;
      // case IoTGatewayProtocolTypeEnum.OPCUA:
      //   // this.Display = 'OPCUA协议';
      //   this.Display = t('iot.enum.ioTGatewayProtocolType.opcua');
      //   this.Color = this.Color ? this.Color : PresetColorEnum.Green;
      //   break;
    }
  }
}

//#region 获取IoT网关协议类型枚举架构
/**
 * 获取IoT网关协议类型枚举架构
 */
export function getIoTGatewayProtocolTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: IoTGatewayProtocolTypeEntity[] = [
    new IoTGatewayProtocolTypeEntity(IoTGatewayProtocolTypeEnum.MQTT),
    // new IoTGatewayProtocolTypeEntity(IoTGatewayProtocolTypeEnum.OPCUA),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.ProtocolType as number,
      label: item.Display,
      value: item.ProtocolType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
